import datetime


# 过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换
now = datetime.datetime.now(tz=None)
now_1 = now.strftime("%Y-%m-%d %H:%M:%S")
print(now)
print(now_1)

now_1 = datetime.datetime.strptime(now_1, "%Y-%m-%d %H:%M:%S")

now_2 = now.timestamp()
now_3 = datetime.datetime.fromtimestamp(now_2, tz=None)
print(now_2)
print(now_3)


# 封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02.
from datetime import timedelta

day_delta = int(input("输入你想要计算的日期，例如，一天前为-1，一天后为1"))
def get_date(day_delta):
    day_c = datetime.datetime.now(tz=None) + timedelta(days=day_delta)
    result = day_c.strftime("%Y-%m-%d %H:%M:%S")
    return(result)
print(get_date(day_delta))
